﻿using System;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Text.RegularExpressions;
using System.Xml.Linq;
using Jungle.Code.DAL;
using Jungle.Code.BLL;
using Jungle.Code.Core;
using Jungle.Code.Utils;


public partial class User : UserControl
{
    protected override void OnInit(EventArgs e)
    {
        if (Request["t"] != null)
        {
            switch (Request["t"])
            {
                case "1": rb_1.Checked = true; break;
                case "2": rb_2.Checked = true; break;
                case "3": rb_3.Checked = true; break;
                default: rb_1.Checked = true; break;
            }
        }
        else
            rb_1.Checked = true;

        btn_Search.PostBackUrl = Request.RawUrl;

        if(Request.QueryString["query"] != null)
            tb_query.Text = Request.QueryString["query"].ToString().ToLower();

        base.OnInit(e); 
    }

    protected override void OnLoad(EventArgs e)
    {
        if (HttpContext.Current.Request.Browser.Browser.IndexOf("Fire") == -1)
        {
            if (Request.RawUrl.IndexOf("Default.aspx?RequestUrl") != -1)
            {
                string t = "";
                if (rb_1.Checked) t = "&t=1";
                if (rb_2.Checked) t = "&t=2";
                if (rb_3.Checked) t = "&t=3";
                Response.Redirect(UrlHelper.GetSiteUrl() + "/ru/search.aspx?query=" + HttpUtility.UrlEncode(tb_query.Text.Trim()) + t);
            }
        }

        base.OnLoad(e);
    }

    protected void Search(object sender, EventArgs e)
    {
        string t = "";
        if (rb_1.Checked) t = "&t=1";
        if (rb_2.Checked) t = "&t=2";
        if (rb_3.Checked) t = "&t=3";
        Response.Redirect(UrlHelper.GetSiteUrl() + "/ru/search.aspx?query=" + HttpUtility.UrlEncode(tb_query.Text.Trim()) + t);
    }
}
